import request from '@/utils/request'
import store from '@/store'
// 查询vipDeadline列表
export function listvipDeadline(query) {
    return request({
        url: '/api/v1/vipDeadlineList',
        method: 'get',
        params: query
    }).then(function (res) {
        
        
        let userLevelOptions = store.getters.parameter.general_user_level;
        res.data.list.forEach((item, index) => {
            // console.log(item)
            for (let key in item) {
                // console.log(key + '---' + item[key])
                
                if (key == "userLevel") {
                    item[key] = getDictLabelByValue(item[key],userLevelOptions)
                }
                //isFamilyOwner

            }
             
            res.data.list[index] = item
        });
        // console.log(res.data.list)
        return res;

    })
}


function getDictLabelByValue(value, dict_list) {
    let dictLabel = "";
    if (dict_list) {
        dict_list.forEach((_item, index) => {
            if (_item.dictValue == value) {
                dictLabel = _item.dictLabel
            }
        })
        return dictLabel;
    } else {
        console.log(value);
        return;
    }

}

// 查询vipDeadline详细
export function getvipDeadline(deadlineId) {
    return request({
        url: '/api/v1/vipDeadline/' + deadlineId,
        method: 'get'
    })
}


// 新增vipDeadline
export function addvipDeadline(data) {
    return request({
        url: '/api/v1/vipDeadline',
        method: 'post',
        data: data
    })
}

// 修改vipDeadline
export function updatevipDeadline(data) {
    return request({
        url: '/api/v1/vipDeadline',
        method: 'put',
        data: data
    })
}

// 删除vipDeadline
export function delvipDeadline(deadlineId) {
    return request({
        url: '/api/v1/vipDeadline/' + deadlineId,
        method: 'delete'
    })
}
